<?php
/**
 * Created by jack.
 * User: liangbo
 * Date: 2017/9/23
 * Time: 上午2:05
 * warning:此代码属于内部版权，未经许可，不得转让
 */


define("DROLE", "注册用户");

/**
 *@功能:判断ajax请求
 * @author 梁波
 *@日期时间:2017/9/23
 */
function isAjax()
{

    if (isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == "xmlhttprequest") {
        return true;
    } else {
        return false;
    };

}

/**
 *@功能:验证邮箱格式
 * @author 梁波
 *@日期时间:2017/9/23
 */
function isEmail($mail)
{
    $checkmail = "/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/"; //用正则表达式函数进行判断
    if (preg_match($checkmail, $mail)) {
        return true;
    } else {
        return false;
    }
}

/**
 *@功能:验证密码复杂度
 * @author 梁波
 *@日期时间:2017/9/23
 */

function isPassword($password)
{
    $preg = "/^[\S]{6,12}$/";
    if (preg_match($preg, $password)) {
        return true;
    } else {
        return false;
    }
}

/**
 *@功能:404页面
 * @author 梁波
 *@日期时间:2017/9/23
 */
function page404()
{
    exit(base64_decode("PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8aGVhZD4KICA8bWV0YSBjaGFyc2V0PSJ1dGYtOCI+CiAgPHRpdGxlPjQwNDwvdGl0bGU+CiAgPG1ldGEgbmFtZT0icmVuZGVyZXIiIGNvbnRlbnQ9IndlYmtpdCI+CiAgPG1ldGEgaHR0cC1lcXVpdj0iWC1VQS1Db21wYXRpYmxlIiBjb250ZW50PSJJRT1lZGdlLGNocm9tZT0xIj4KICA8bWV0YSBuYW1lPSJ2aWV3cG9ydCIgY29udGVudD0id2lkdGg9ZGV2aWNlLXdpZHRoLCBpbml0aWFsLXNjYWxlPTEsIG1heGltdW0tc2NhbGU9MSI+CiAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSIvL3Jlcy5sYXl1aS5jb20vbGF5dWkvZGlzdC9jc3MvbGF5dWkuY3NzIiAgbWVkaWE9ImFsbCI+CjwvaGVhZD4KPGJvZHk+CjxmaWVsZHNldCBjbGFzcz0ibGF5dWktZWxlbS1maWVsZCBsYXl1aS1maWVsZC10aXRsZSIgc3R5bGU9Im1hcmdpbi10b3A6IDMwcHg7Ij4KICA8bGVnZW5kPjQwNDwvbGVnZW5kPgo8L2ZpZWxkc2V0PgogCjx1bCBjbGFzcz0ic2l0ZS1kb2MtaWNvbiI+CiAgPGxpPgogICAgPGRpdiBjbGFzcz0ibGF5dWktYW5pbSIgZGF0YS1hbmltPSJsYXl1aS1hbmltLXVwIj40MDQ8L2Rpdj4KPC91bD4gICAgICAgICAgCiAgICAgICAgICAgICAgIAogICAgICAgICAgCjxzY3JpcHQgc3JjPSIvL3Jlcy5sYXl1aS5jb20vbGF5dWkvZGlzdC9sYXl1aS5qcyIgY2hhcnNldD0idXRmLTgiPjwvc2NyaXB0Pgo8IS0tIOazqOaEj++8muWmguaenOS9oOebtOaOpeWkjeWItuaJgOacieS7o+eggeWIsOacrOWcsO+8jOS4iui/sGpz6Lev5b6E6ZyA6KaB5pS55oiQ5L2g5pys5Zyw55qEIC0tPgo8c2NyaXB0Pgo8L3NjcmlwdD4KCjwvYm9keT4KPC9odG1sPg=="));
}

/**
 *@功能:没有权限的页面
 * @author 梁波
 *@日期时间:2017/9/23
 */

function page500()
{
    exit(base64_decode("PCFET0NUWVBFIGh0bWw+CjxodG1sPgogIDxoZWFkPgogICAgPHRpdGxlPuW+ruS/oeacuuWZqOS6uuS6keW5s+WPsDwvdGl0bGU+CiAgICA8bWV0YSBjaGFyc2V0PSJ1dGYtOCI+CjxtZXRhIGh0dHAtZXF1aXY9IlgtVUEtQ29tcGF0aWJsZSIgY29udGVudD0iSUU9ZWRnZSI+CjxtZXRhIG5hbWU9InZpZXdwb3J0IiBjb250ZW50PSJ3aWR0aD1kZXZpY2Utd2lkdGgsIGluaXRpYWwtc2NhbGU9MSwgdXNlci1zY2FsYWJsZT1ubyI+CjxsaW5rIHJlbD0ic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WZqOS6uuS6keW5s+WPsDwvYT4KICAgICAgICAgIDwvcD4KICAgICAgPC9kaXY+CiAgICA8L2Rpdj4KICAgPC9ib2R5Pgo8L2h0bWw+"));

}

/**
 *@功能:生成随机验证码
 * @author 梁波
 *@日期时间:2017/9/23
 */
function randYzm()
{

    return rand(10000, 99999);

}

/**
 *@功能:生成uuid
 * @author 梁波
 *@日期时间:2017/10/6
 */
function get_uuid($prefix = "")
{    //可以指定前缀
    $str = md5(uniqid(mt_rand(), true));
    $uuid = substr($str, 0, 8) . '-';
    $uuid .= substr($str, 8, 4) . '-';
    $uuid .= substr($str, 12, 4) . '-';
    $uuid .= substr($str, 16, 4) . '-';
    $uuid .= substr($str, 20, 12);
    return $prefix . $uuid;
}

/**
 *@功能:监控机器人运行状态
 * @author 梁波
 *@日期时间:2017/10/7
 */

function robot_status($status)
{

    if ($status == 1)
        return "<span class='btn-success'>start</span>";
    else

        return "<span class='btn-danger'>stop</span>";

}

function status_message($status)
{
    if($status)
        return '<span class="pull-center badge bg-green">启用</span>';
    else
        return '<span class="pull-center badge bg-red">未启用</span>';
}

function _cut($begin,$end,$str){
    $b = mb_strpos($str,$begin) + mb_strlen($begin);
    $e = mb_strpos($str,$end) - $b;

    return mb_substr($str,$b,$e);
}

